package com.xinchen.gufeiwulian.ui.activity

import android.os.Bundle
import android.widget.ImageButton
import androidx.activity.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.maple.base.base.BaseActivity
import com.maple.model.data.MainMenuData
import com.maple.utils.ext.toVisible
import com.xinchen.gufeiwulian.R
import com.xinchen.gufeiwulian.ui.adapter.MainMenuAdapter
import com.xinchen.gufeiwulian.vm.HomeViewModel

class MenuMoreActivity : BaseActivity() {

    private var rvList: RecyclerView? = null

    private val menus: MutableList<MainMenuData> = mutableListOf()


    private val listAdapter: MainMenuAdapter by lazy {
        MainMenuAdapter(this).apply {
            this.setListener(object : MainMenuAdapter.OnClickListener{
                override fun onItemClick(pos: Int, item: MainMenuData?) {
                    item?.let {
                        when(it.name) {
                            "入库" -> {

                            }
                            "出库" -> {

                            }
                        }
                    }
                }
            })
        }
    }


    private val viewModel by viewModels<HomeViewModel>()
    override fun getLayoutId(): Int = R.layout.activity_menu_more

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        setTitle("更多")
        findViewById<ImageButton>(com.maple.res.R.id.ibtn_title_left)?.let {
            it.toVisible()
            it.setOnClickListener {
                this.onFinish()
            }
        }

        rvList = findViewById(R.id.rv_list)
        rvList?.let {
            val manager: GridLayoutManager = GridLayoutManager(this,4)
            manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    val itemType = it.adapter?.getItemViewType(position)
                    if(itemType == MainMenuAdapter.TYPE_HEADER) {
                        return 4
                    }
                    return 1
                }
            }

            it.layoutManager = manager
            it.adapter = listAdapter
        }
    }
    override fun initData(savedInstanceState: Bundle?) {
        menus.add(MainMenuData("入库", R.drawable.ic_menu_ruku))
        menus.add(MainMenuData("出库", R.drawable.ic_menu_chuku))
        menus.add(MainMenuData("标签查询", R.drawable.ic_menu_biaoqianchaxun))
        menus.add(MainMenuData("标签管理", R.drawable.ic_menu_biaoqianguanli))
        menus.add(MainMenuData("收集", R.drawable.ic_menu_shouji))
        menus.add(MainMenuData("装箱", R.drawable.ic_menu_zhuangxiang))
        menus.add(MainMenuData("跨省出库", R.drawable.ic_menu_kuashengchuku))
        menus.add(MainMenuData("待拉运", R.drawable.ic_menu_dailayun))

        listAdapter.setData(menus)
    }

}